<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {:widget_st('layui','css')}
  {:widget_st('admin','css')}
  {:widget_st('bootstrap')}
  {:widget_st('jq','js')}
  {:widget_st('layui','js')}
  {:widget_st('common','js')}
</head>
{:do_action('admin_head')}
<body>
  <div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
          <div class="layui-form-item">
            <form method="get">
              <div class="layui-inline">
                <label class="layui-form-label">关键词</label>
                <div class="layui-input-block">
                  <input type="text" name="keyword" placeholder="请输入" autocomplete="off" class="layui-input" value="{$keyword}">
                </div>
              </div>
              <div class="layui-inline">
                  <button class="layui-btn" ><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i></button>
              </div>
            </form>
              <div class="layui-inline">
              </div>
            <a class="layui-btn layui-btn-sm layui-btn-normal" href="?where_type="> 全部</a>


            <!-- <a class="layui-btn up_file" >导入产品</a> -->
              <!-- <a href="/upload/产品导入参考.xlsx" target="_blank">参考文件</a> -->

            
              &nbsp;
              &nbsp;
              &nbsp;
              &nbsp;
              <!-- <a class="layui-btn" target="_blank" href="{:url('category/export_pro')}">导出产品</a>
              <a class="layui-btn up_file2" >导入产品(编辑)</a> -->
            
          </div>
        </div>
      <div class="layui-card-body">
        <a class="zf_all_check">全选</a>
        <span class="pl_del" style="color: red;">批量删除</span>
        <table class="layui-table">
            <colgroup>
             
              <col>
            </colgroup>
            <thead>
              <tr>
                <th>ID</th>
                <th>标题</th>
                <th>分组</th>
                <th>推荐</th>
                <th>状态</th>
                <th>操作</th>
              </tr> 
            </thead>
            <tbody>
              <?php foreach($list as $k=>$vo){ ?>
                <tr>
                  <td>
                    <input type="checkbox" name="ids[]" value="{$vo['id']}" >
                    {$vo['id']}
                  </td>
                  <td>{$vo['title']}</td>
                  <td>
                    {:get_cate_name('category',$vo['cid'])}
                  </td>
                  <td> 
                    <div class=" layui-form" lay-filter="component-form-element">        
                       <input type="checkbox" name="recommend" <?php echo $vo['recommend']==1?'checked':''; ?> lay-skin="switch" lay-text="开启|关闭" lay-filter="recommend_change" item="{$vo['id']}">
                    </div>
                  </td>  
                  <td> 
                    <div class=" layui-form" lay-filter="component-form-element">        
                       <input type="checkbox" name="status" <?php echo $vo['status']==1?'checked':''; ?> lay-skin="switch" lay-text="开启|关闭" lay-filter="status_change" item="{$vo['id']}">
                    </div>
                  </td>                
                  <td> 
                    <a class="layui-btn btn_del layui-btn-danger layui-btn-sm" rel="{$vo['id']}" href="#">删除</a> 
                    <button class="layui-btn layui-btn-sm" onclick='zfAdminShow("编辑","{:url('admin/category/post_add',['id' => $vo['id'],'cid' => $vo['cid'],'mid' => 10] )}")'>编辑</button> 
                    <!-- <a  class="layui-btn layui-btn-sm" href="{:url('admin/category/post_add',['id' => $vo['id'],'cid' => $vo['cid'],'mid' => 10] )}" target="_blank"> 编辑(新页面打开)</a> -->
                    
                  
                  </td>
                </tr>
              <?php } ?>         
            </tbody>
          </table>
          {$page|raw}

      </div>
    </div>
  </div>
  


  <script>
 layui.use([ 'table','element','layer','upload'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,table = layui.table
    ,layer = layui.layer
    ,upload = layui.upload;

    upload.render({
      elem: '.up_file'
      ,url: "{:url('admin/category/import_pro')}"
      ,accept: 'file' 
      ,done: function(res){
        console.log(res);
        if(res.result==1){
            layer.msg(res.msg, {icon: 1});
            setTimeout(function() {
              window.location.reload();
            }, 2000);
        }else{
          layer.msg(res.msg, {icon: 2});
        }
      }
      ,error: function(){
          layer.msg(res.msg, {icon: 2});
      }
    });
    upload.render({
      elem: '.up_file2'
      ,url: "{:url('admin/category/import_pro_edit')}"
      ,accept: 'file' 
      ,done: function(res){
        console.log(res);
        if(res.result==1){
            layer.msg(res.msg, {icon: 1});
            setTimeout(function() {
              window.location.reload();
            }, 2000);
        }else{
          layer.msg(res.msg, {icon: 2});
        }
      }
      ,error: function(){
          layer.msg(res.msg, {icon: 2});
      }
    });
    

    form.on('switch(status_change)', function(data){
      var id = $(this).attr("item")
      var dbname = 'post'
      var status = this.checked ? '1' : '0'
      console.log(id)
      $.get("{:url('admin/common/is_switch')}",{id:id,dbname:dbname,status:status},function(res){
          if(res.result==1){
            layer.msg(res.msg, {icon: 1});
          }else{
            layer.msg(res.msg, {icon: 2});
          }
        },"json");
    });
     form.on('switch(recommend_change)', function(data){
      var id = $(this).attr("item")
      var dbname = 'post'
      var status = this.checked ? '1' : '0'
      console.log(id)
      $.get("{:url('admin/common/is_recommend')}",{id:id,dbname:dbname,status:status},function(res){
          if(res.result==1){
            layer.msg(res.msg, {icon: 1});
          }else{
            layer.msg(res.msg, {icon: 2});
          }
        },"json");
    });

    //选中
    $('.zf_all_check').on('click',function(){
      var check = $(this).text();
      if(check=='全选'){
        $('input[name="ids[]"]').prop('checked',true);
        $(this).text('取消');
      }else{
        $('input[name="ids[]"]').prop('checked',false);
        $(this).text('全选');
      }
    })
    //批量删除
    $('.pl_del').on('click',function(){
      var ids = [];
      $('input[name="ids[]"]:checked').each(function(){
        ids.push($(this).val());
      });
      if(ids.length==0){
        layer.msg('请选择要删除的数据', {icon: 2});
        return false;
      }
      layer.confirm('确认删除？', {
        btn: ['删除','取消']
      }, function(){
        $.get("{:url('admin/common/more_del')}",{ids:ids,dbname:'post'},function(res){
          if(res.result==1){
            layer.msg("删除成功", {icon: 1});
            setTimeout(function() {
              location.reload(true);
            }, 1000);
          }else{
            layer.msg(res.msg, {icon: 2});
            
          }
        },"json");

      }, function(){
          //取消的操作
      });
    })
    
    // 删除
    $(".btn_del").on("click",function(){
      var id = $(this).attr("rel");
      layer.confirm('确认删除？', {
        btn: ['删除','取消']
      }, function(){
        
        $.get("{:url('admin/common/del_post')}",{id:id,db:'post'},function(res){
          if(res.result==1){
            layer.msg("删除成功", {icon: 1});
            setTimeout(function() {
              location.reload(true);
            }, 1000);
          }else{
            layer.msg(res.msg, {icon: 2});
            
          }
        },"json");

      }, function(){
          //取消的操作
      });
    })
  });
  </script>
</body>
</html>
{:do_action('admin_js')}
